<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head>
  <link href="//gmpg.org/xfn/11" rel="profile">
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="generator" content="Hugo 0.69.0" />

  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Git安装以及常用的命令 &middot; 郝朝帅的博客</title>

  
  <link type="text/css" rel="stylesheet" href="/blog/css/print.css" media="print">
  <link type="text/css" rel="stylesheet" href="/blog/css/poole.css">
  <link type="text/css" rel="stylesheet" href="/blog/css/syntax.css">
  <link type="text/css" rel="stylesheet" href="/blog/css/hyde.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Abril+Fatface|PT+Sans:400,400i,700">


  
  <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144-precomposed.png">
  <link rel="shortcut icon" href="/favicon.png">

  
  
</head>

  <body class="theme-base-0f ">
  <aside class="sidebar">
  <div class="container sidebar-sticky">
    <div class="sidebar-about">
      <a href="/blog/"><h1>郝朝帅的博客</h1></a>
      <p class="lead">
       我的个人博客 
      </p>
    </div>

    <nav>
      <ul class="sidebar-nav">
        <li><a href="/blog/">Home</a> </li>
        
      </ul>
    </nav>

    <p>&copy; 2020. All rights reserved. </p>
  </div>
</aside>

    <main class="content container">
    <div class="post">
  <h1>Git安装以及常用的命令</h1>
  <time datetime=2020-04-25T20:01:49&#43;0800 class="post-date">Sat, Apr 25, 2020</time>
  <h1 id="git">GIT</h1>
<h4 id="安装版本是2261-64-bit">安装(版本是：2.26.1-64-bit)</h4>
<ol>
<li>
<p>​	第一步点击安装包</p>
</li>
<li>
<p>第二步点击Next</p>
<p><img src="https://gitee.com/hao695402632/blog/tree/master/day01/image-20200426132704534.png" alt="image-20200426132704534"></p>
</li>
<li>
<p>第三步选定安装位置，然后点击Next</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426132905720.png" alt="image-20200426132905720"></p>
</li>
<li>
<p>第四步一些扩展，不需要懂，然后直接点击Next</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426133123462.png" alt="image-20200426133123462"></p>
</li>
<li>
<p>第五步在，然后点击Next</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426133419226.png" alt="image-20200426133419226"></p>
</li>
<li>
<p>第六步，这些是告诉你用什么编辑器，我们默认编辑器是Vim,所以也不需要动他，然后点击Next</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426133630005.png" alt="image-20200426133630005"></p>
</li>
<li>
<p>第七步是配置环境变量就用默认的推荐(<em>Recommended</em>的就行，也不用动,直接Next</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426133923947.png" alt="image-20200426133923947"></p>
</li>
<li>
<p>第八步是选择证书，默认是OpenSSL，直接点击Next</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426134452699.png" alt="image-20200426134452699"></p>
</li>
<li>
<p>第九步是Checkout风格，我用的是Windows，所以选第一个，如果是Linux就选第二个，然后点击Next</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426134611113.png" alt="image-20200426134611113"></p>
</li>
<li>
<p>第十步是选择窗口模式，第一个是迷你窗口，第二个是cmd的命令行，我选择的是默认的迷你窗口，然后点击Next</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426135015653.png" alt="image-20200426135015653"></p>
</li>
<li>
<p>第十一步git操作需要不需要系统缓存，选择第一个启用文件系统缓存，选择第二个启用Git凭据管理器，第三个我们不需要就不选择，然后点击install</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426135353229.png" alt="image-20200426135353229"></p>
</li>
<li>
<p>然后就开始安装了</p>
</li>
</ol>
<h4 id="环境变量">环境变量</h4>
<ol>
<li>
<p>找到控制面板主页</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426225708291.png" alt="image-20200426225708291"></p>
</li>
<li>
<p>点击系统</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426235704926.png" alt="image-20200426235704926"></p>
</li>
<li>
<p>点击左边高级系统管理</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426235810984.png" alt="image-20200426235810984"></p>
</li>
<li>
<p>点击下面的环境变量</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426235902740.png" alt="image-20200426235902740"></p>
</li>
<li>
<p>编辑用户变量以及编辑系统变量里的path，</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200427000425417.png" alt="image-20200427000425417"></p>
</li>
<li>
<p>点击右边的新建，把你应用的目录路径添加进去</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200427000809432.png" alt="image-20200427000809432"></p>
</li>
<li>
<p>然后一直点击确定就好了</p>
</li>
</ol>
<h4 id="git卸载">Git卸载</h4>
<ol>
<li>
<p>​	找到控制面板主页</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426225708291.png" alt="image-20200426225708291"></p>
</li>
<li>
<p>点击程序和功能</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426225832484.png" alt="image-20200426225832484"></p>
</li>
<li>
<p>找到Git version，右键点击卸载</p>
<p><img src="C:%5CUsers%5C69540%5Cstudent%5Cblog%5Cstatic%5Cday01%5Cimage-20200426225939309.png" alt="image-20200426225939309"></p>
</li>
</ol>
<h4 id="git命令">Git命令</h4>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#75715e"># 克隆网上的项目</span>
git clone https:<span style="color:#f92672">//</span>gitee<span style="color:#f92672">.</span>com<span style="color:#f92672">/....</span>

<span style="color:#75715e"># 云端拉取最新代码</span>
git pull origin master

<span style="color:#75715e"># Git设置</span>
git config <span style="color:#f92672">--</span><span style="color:#66d9ef">global</span> user<span style="color:#f92672">.</span>name <span style="color:#e6db74">&#34;**的技术博客&#34;</span>
git config <span style="color:#f92672">--</span><span style="color:#66d9ef">global</span> user<span style="color:#f92672">.</span>email <span style="color:#e6db74">&#34;*******@user.noreply.gitee.com&#34;</span>

<span style="color:#75715e"># 创建文件夹</span>
mkdir filename

<span style="color:#75715e"># 进入文件夹</span>
cd filename

<span style="color:#75715e"># 初始化本地版本库(创建一个.git文件)</span>
git init

<span style="color:#75715e"># 添加所有文件及文件夹到本地暂停区</span>
git add <span style="color:#f92672">-</span>A

<span style="color:#75715e"># 添加指定的文件或文件夹到本地暂停区</span>
git add filename

<span style="color:#75715e"># 提交添加的文件或文件夹到版本库</span>
git commit <span style="color:#f92672">-</span>m <span style="color:#e6db74">&#34;first commit&#34;</span>

<span style="color:#75715e"># 把本地的代码和线上的代码形成映射关系</span>
git remote add origin https:<span style="color:#f92672">//</span>gitee<span style="color:#f92672">.</span>com<span style="color:#f92672">/***.</span>git

<span style="color:#75715e"># 推送代码上传到百度云</span>
git push <span style="color:#f92672">-</span>u origin master
</code></pre></div><div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#75715e">#回退代码</span>

<span style="color:#75715e"># 查看commit日志</span>
git log

<span style="color:#75715e"># 硬性回退(回退到哪就找commit日志里的commitID)</span>
git reset <span style="color:#f92672">--</span>hard commitID

<span style="color:#75715e"># 强迫云端的代码要根据本地的代码变成一致</span>
git push origin HEAD <span style="color:#f92672">--</span>force
</code></pre></div><p>注意：注意建立完是红色的，表示还未添加，add之后是绿色的，做过修改是蓝色的，忽略的文件是灰色的</p>

</div>


    </main>

    
  </body>
</html>
